home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_319 / cnewssrc / cnews.orig.lzh / expire / upact < prev   
Text File  |  1989-06-27  |  1KB  |  61 lines

  1. #! /bin/sh
  2. # Update 3rd field (minimum art. #) of a 4-field active file.
  3.  
  4. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  5. . ${NEWSCONFIG-/usr/lib/news/bin/config}
  6.  
  7. PATH=$NEWSCTL/bin:$NEWSBIN/expire:$NEWSBIN:$NEWSPATH ; export PATH
  8. umask $NEWSUMASK
  9.  
  10. cd $NEWSCTL || { echo "$0: can't cd to $NEWSCTL" >&2; exit 1; }
  11.  
  12. # check active file format
  13. set ""`sed 1q active`
  14. case $# in
  15. 4)    ;;
  16. *)    echo "$0: active file has other than 4 fields" >&2
  17.     exit 1 ;;
  18. esac
  19.  
  20. # lock news system
  21. lock="$NEWSCTL/LOCK"
  22. ltemp="$NEWSCTL/L.$$"
  23. echo $$ >$ltemp
  24. trap "rm -f $ltemp ; exit 0" 0 1 2 15
  25. while true
  26. do
  27.     if newslock $ltemp $lock
  28.     then
  29.         trap "rm -f $ltemp $lock ; exit 0" 0 1 2 15
  30.         break
  31.     fi
  32.     sleep 30
  33. done
  34.  
  35. while read group max min fourth
  36. do
  37.     dir=`echo $group | tr . / `    # map ng name to directory name
  38.     min=
  39.     if test -d $NEWSARTS/$dir
  40.     then
  41.         # min=`lowest $NEWSARTS/$dir`
  42.         min=`ls $NEWSARTS/$dir | egrep '^[0-9]+$' | sort -nr | tail -1`
  43.     fi
  44.     case "$min" in        # no files, so
  45.     "")    min=$max ;;    # use maximum
  46.     esac
  47.     case "$min" in
  48.     [0-9]|[0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9])    # short
  49.         min=`expr 00000$min : '.*\(.....\)$'` ;;
  50.     esac
  51.  
  52.     echo $group $max $min $fourth
  53. done <active >active.new
  54.  
  55. # replace active, carefully
  56. rm -f active.old
  57. ln active active.old
  58. mv active.new active
  59.  
  60. exit 0
  61.